﻿namespace CommonUtils
{
    /// <summary>
    /// Windows服务
    /// </summary>
    public class ServiceUtil
    {
        /// <summary>
        /// 注册IIS
        /// </summary>
        public static void RegistIIS()
        => ProcessUtil.Run(@"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe", "-i");

        /// <summary>
        /// 安装服务
        /// </summary>
        public static void Install(string path)
        => ProcessUtil.Run(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe", path.AddDoubleQuotes());

        /// <summary>
        /// 卸载服务
        /// </summary>
        public static void Uninstall(string path)
        => ProcessUtil.Run(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe", "/u " + path.AddDoubleQuotes());

        /// <summary>
        /// 卸载服务
        /// </summary>
        public static void UninstallByName(string name)
        => ProcessUtil.Run("sc", "delete " + name.AddDoubleQuotes());
    }
}
